﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace HareGame
{
    /// <summary>
    /// 游戏配置
    /// </summary>
    [Serializable]
    public class GameConfig
    {

    }

    /// <summary>
    /// 测试配置
    /// </summary>
    [Serializable]
    public class TestConfig
    {
        /// <summary>
        /// 是否显示测试按钮
        /// </summary>
        public bool ShowTestButton = true;

        /// <summary>
        /// 广告开关
        /// </summary>
        public bool AdOpen = false;

        /// <summary>
        /// 显示FPS
        /// </summary>
        public bool ShowFPS = false;

        /// <summary>
        /// 显示控制台Log
        /// </summary>
        public bool ShowConsole = false;
    }


    /// <summary>
    /// 可被序列化的List
    /// </summary>
    /// <typeparam name="T"></typeparam>
    [Serializable]
    public class Serialization<T>
    {
        [SerializeField]
        List<T> Data;
        public List<T> ToList() { return Data; }

        public Serialization(List<T> data)
        {
            this.Data = data;
        }
    }

    /// <summary>
    /// 可被序列化的Dictionary
    /// </summary>
    /// <typeparam name="TKey">键</typeparam>
    /// <typeparam name="TValue">值</typeparam>
    [Serializable]
    public class Serialization<TKey, TValue> : ISerializationCallbackReceiver
    {
        [SerializeField]
        List<TKey> keys;
        [SerializeField]
        List<TValue> values;

        Dictionary<TKey, TValue> Data;
        public Dictionary<TKey, TValue> ToDictionary() { return Data; }

        public Serialization(Dictionary<TKey, TValue> data)
        {
            this.Data = data;
        }

        public void OnBeforeSerialize()
        {
            keys = new List<TKey>(Data.Keys);
            values = new List<TValue>(Data.Values);
        }

        public void OnAfterDeserialize()
        {
            var count = Math.Min(keys.Count, values.Count);
            Data = new Dictionary<TKey, TValue>(count);
            for (var i = 0; i < count; ++i)
            {
                Data.Add(keys[i], values[i]);
            }
        }
    }
}